/**
 *码值转化
 @params:val arr
 @return:“-”或“男”或“陕西省，咸阳市，秦都区”
 */
export function codeName(val = '', arr = []) {
    if (val === null || val === undefined || val === '') return '--';
    if (arr === null || arr === undefined || arr === []) return val;

    if (typeof val === 'string' && val.includes(',')) {
        let list = val.split(',');
        let transList = '';
        list.forEach( item => {
            let NList = arr.filter(code => {
                if (code.codeValue) {
                    return code.codeValue === item;
                } else if (code.codeName) {
                    return code.codeName === item;
                } else {
                    return [];
                }
            });
            let NSTR = NList.length ? NList[0].codeName : '';
            transList += NSTR + ',';
        });
        transList = transList.substring(0, transList.length - 1);
        return transList;
    } else {
        const CList = arr.filter(code => {
            if (code.codeValue) {
                return code.codeValue === val;
            } else if (code.codeName) {
                return code.codeName === val;
            } else {
                return [];
            }
        });
        return CList.length ?  CList[0].codeName : '-'
    }
}

